package com.chain.qs.modules.biz.service;

import com.chain.qs.common.service.CrudService;
import com.chain.qs.modules.biz.dao.EquipmentDao;
import com.chain.qs.modules.biz.dao.EquipmentGroupDao;
import com.chain.qs.modules.biz.entity.Equipment;
import com.chain.qs.modules.biz.entity.EquipmentGroup;
import com.chain.qs.modules.biz.entity.EquipmentGroupItem;
import com.chain.qs.modules.biz.entity.StationGroup;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


/**
 * 设备Service
 *
 * @author wangzhiping
 */
@Service
//@Transactional(readOnly = true)
public class EquipmentGroupService extends CrudService<EquipmentGroupDao, EquipmentGroup> {
    @Resource
    private EquipmentGroupItemService equipmentGroupItemService;
    @Resource
    private StationGroupService stationGroupService;

    public List<EquipmentGroup> findListByType(int type) {
        return dao.findListByType(type);
    }

    @Transactional(readOnly = false)
    public void delete(EquipmentGroup equipmentGroup) {
        for (EquipmentGroupItem equipmentGroupItem : equipmentGroupItemService.findListByGroupId(equipmentGroup.getId())) {
            equipmentGroupItemService.delete(equipmentGroupItem);
        }
        for (StationGroup stationGroup : stationGroupService.findListByGroupId(equipmentGroup.getId())) {
            stationGroupService.delete(stationGroup);
        }
        super.delete(equipmentGroup);
    }
}
